package com.sfdk.core.abstract
{
import com.sfdk.core.GameProxy;
import com.sfdk.graphics.core.MovieClipEx;

public class AbstractState
	{
		protected var _gameProxy : GameProxy;
		protected var _view : MovieClipEx;
		
		public function AbstractState(gameProxy : GameProxy, view : MovieClipEx = null, parameters : Object = null)
		{
			_gameProxy = gameProxy;
			_view = view;
			initState(parameters);	
		}
		
		/**
		 * First thing that is done when creating a new state
		 */
		protected function initState(parameters : Object = null) : void
		{
			if(_view != null)
				_gameProxy.attachChild(_view, 0, 0, "stateView", "none", "none");
		}
		
		
		protected function stateLoaded() : void
		{
			_gameProxy.stateLoaded();
		}
		/**
		 * Used to clean up the state before switching to another state
		 */
		public function endState() : void
		{
			if(_view != null)
			{
				_view.removeAllChildren();
				_gameProxy.removeChild(_view);
			}
		}
		
		public function get view() : MovieClipEx
		{
			return _view;
		}
	}
}